package com.larson.creator.view
{
	import flash.events.Event;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
    import com.larson.creator.*;
    import com.larson.creator.model.*;
	import com.larson.creator.view.components.*;
		
	public class controlScreenMediator extends Mediator implements IMediator
	{
        // Cannonical name of the Mediator
        public static const NAME:String = "controlScreenMediator";
        
        /**
         * Constructor. 
         */
		public function controlScreenMediator (viewComponent:controlScreen)
		{
            // pass the viewComponent to the superclass where 
            // it will be stored in the inherited viewComponent property
            super( NAME, viewComponent );
            
            this.crs.addEventListener( controlScreen.GET_FILE, this.handleGetFile );
            this.crs.addEventListener( controlScreen.CONVERT_FILE, this.handleConvertFile );
            this.crs.addEventListener( controlScreen.EL_CORRECT, this.handleElevationCorrection );
		}
		
		
        /**
         * List all notifications this Mediator is interested in.
         * <P>
         * Automatically called by the framework when the mediator
         * is registered with the view.</P>
         * 
         * @return Array the list of Nofitication names
         */
        override public function listNotificationInterests():Array 
        {
        	
            return [ 
					ApplicationFacade.LOAD_FILE_COMPLETE
					//ApplicationFacade.LOADING_COMPLETE,
					//ApplicationFacade.LOAD_CONFIG_FAILED,
					//ApplicationFacade.LOAD_RESOURCE_FAILED
					];
					
			//return new Array();
        }

        /**
         * Handle all notifications this Mediator is interested in.
         * <P>
         * Called by the framework when a notification is sent that
         * this mediator expressed an interest in when registered
         * (see <code>listNotificationInterests</code>.</P>
         * 
         * @param INotification a notification 
         */
        override public function handleNotification( note:INotification ):void 
        {
            switch ( note.getName() ) 
			{
				/*
				case ApplicationFacade.LOADING_STEP:
					// update the progress barr
					this.splashScreen.pb.setProgress( note.getBody() as int, 100);
					break;
					
				case ApplicationFacade.LOADING_COMPLETE:
					// all done
					// show the main screen
					this.sendNotification( ApplicationFacade.VIEW_MAIN_SCREEN );
					break;
					
				case ApplicationFacade.LOAD_CONFIG_FAILED:
				*/
				case ApplicationFacade.LOAD_FILE_COMPLETE:
					crs.cVO.fileStatus = true;
					break;
				

            }
        }

        /**
         * Cast the viewComponent to its actual type.
         * 
         * <P>
         * This is a useful idiom for mediators. The
         * PureMVC Mediator class defines a viewComponent
         * property of type Object. </P>
         * 
         * <P>
         * Here, we cast the generic viewComponent to 
         * its actual type in a protected mode. This 
         * retains encapsulation, while allowing the instance
         * (and subclassed instance) access to a 
         * strongly typed reference with a meaningful
         * name.</P>
         * 
         * @return SplashScreen the viewComponent cast to org.puremvc.as3.demos.flex.appskeleton.view.components.SplashScreen
         */
		 
        protected function get crs():controlScreen
		{
            return viewComponent as controlScreen;
        }
		
		private function handleGetFile(event:Event):void
		{
			sendNotification( ApplicationFacade.COMMAND_FILE_LOAD );
			
		}
		
		private function handleConvertFile(event:Event):void
		{
			sendNotification( ApplicationFacade.COMMAND_FILE_CONVERT, crs.cVO );
			
		}
		
		private function handleElevationCorrection(event:Event):void
		{
			sendNotification( ApplicationFacade.COMMAND_ELEVATION_CORRECT, crs.cVO );
			
		}
		


	}
}